var $table = $('#table');
var $tablez1 = $('#table_z1');

var $caddbtn = $("#cadd");
var $queryBtn = $('#queryBtn');
var $cedit = $('#cedit');
var $cdel = $('#cdel');
var $cimp = $('#cimp');
var $ccal = $('#cal');

var $z1addbtn = $("#z1add");
var $z1edit = $('#z1edit');
var $z1del = $('#z1del');
var $z1imp = $('#z1imp');


var uploader;
var $list;

var $cexp = $('#cexp');
var $z1cexp = $('#z1cexp');

$(function () {

    $('.form-control-chosen').chosen({
        allow_single_deselect: true,
        width: '100%'
    });

    $ccal.click(function () {

        var info = $table.bootstrapTable('getSelections');

        if (info.length != 1) {
            rapid.info("请选择一行计算!");
        } else {

            rapid.post({
                url: "/sysadmin/model/calModel",
                data: "cid=" + info[0].conflict_id,
                success: function (result) {
                    alert("!!!");
                    $table.bootstrapTable('refresh', {query: {pageIndex: 0, pageSize: 10}});
                    $tablez1.bootstrapTable('refresh', {query: {pageIndex: 0, pageSize: 10}});
                },
                fail:function (result) {

                    rapid.error("选定字段其中有字段值不可计算!");
                    $table.bootstrapTable('refresh', {query: {pageIndex: 0, pageSize: 10}});
                    $tablez1.bootstrapTable('refresh', {query: {pageIndex: 0, pageSize: 10}});
                }
            });


        }
    });

    $list = $("#thelist");
    var $btn = $("#ctlBtn");   //开始上传


    __bindRdetailformuploadinit = function () {
        // 初始化Web Uploader

        uploader = WebUploader.create({

            // 选完文件后，是否自动上传。
            auto: false,

            // swf文件路径
            swf: '/script/pc/sysmgt/dbcontact/Uploader.swf',

            // 文件接收服务端。
            server: '/comm/api/webUpload',

            // 选择文件的按钮。可选。
            // 内部根据当前运行是创建，可能是input元素，也可能是flash.
            pick: '#picker',

            fileSingleSizeLimit: 15 * 1024 * 1024,   //设定单个文件大小
            //限制只能上传一个文件
            //fileNumLimit: 1,

            // 只允许选择图片文件。
            accept: {
                extensions: "xls,xlsx",
                mimeTypes: ".xls,.xlsx"
            }
        });

        //点击上传按钮触发事件
        $btn.click(function () {

            uploader.upload();


        });


        // 当有文件添加进来的时候
        uploader.on('fileQueued', function (file) {

            for (var i = 0; i < uploader.getFiles().length - 1; i++) {
                // 将图片从上传序列移除\

                // uploader.removeFile(uploader.getFiles()[i]);
                uploader.removeFile(uploader.getFiles()[i], true);
                delete uploader.getFiles()[i];
                // 将图片从缩略图容器移除
                var $li = $('#' + uploader.getFiles()[i].id);
                $li.off().remove();
            }

            $list.append('<div id="' + file.id + '" class="item">' +
                '<h4 class="info">' + file.name + '</h4>' +
                '<p class="state">等待上传...</p>' +
                '</div>');
        });

// 文件上传过程中创建进度条实时显示。
        uploader.on('uploadProgress', function (file, percentage) {
            var $li = $('#' + file.id),
                $percent = $li.find('.progress .progress-bar');

            // 避免重复创建
            if (!$percent.length) {
                $percent = $('<div class="progress progress-striped active">' +
                    '<div class="progress-bar" role="progressbar" style="width: 0%">' +
                    '</div>' +
                    '</div>').appendTo($li).find('.progress-bar');
            }

            $li.find('p.state').text('上传中');

            $percent.css('width', percentage * 100 + '%');
        });


        uploader.on('uploadSuccess', function (file, response) {

            $("#hideFileName").val(response.data)
            $('#' + file.id).find('p.state').text('已上传');
        });

        uploader.on('uploadError', function (file) {
            $('#' + file.id).find('p.state').text('上传出错');
        });

        uploader.on('uploadComplete', function (file) {
            $('#' + file.id).find('.progress').fadeOut();
        });


    }


    $cedit.click(function () {

        var info = $table.bootstrapTable('getSelections');

        if (info.length != 1) {
            rapid.info("请选择一行编辑!");
        } else {

            rapid.post({
                url: "/sysadmin/model/getModellist",
                data: "cid=" + info[0].conflict_id,
                success: function (result) {
                    $("#myModal").modal();
                    $("#conflict_id").val(result.conflict_id);
                    $("#cid").val(result.row_id);
                    $("#attrib_01 option[value='" + result.attrib_07 + "']").prop("selected", true);
                    $("#attrib_06 option[value='" + result.attrib_06 + "']").prop("selected", true);
                    $("#attrib_03 option[value='" + result.attrib_03 + "']").prop("selected", true);
                    modelnamelist();
                }
            });


        }
    });
function choseattrib_03() {
    var info = $table.bootstrapTable('getSelections');
    rapid.post({
        url: "/sysadmin/model/getModellist",
        data: "cid=" + info[0].conflict_id,
        success: function (result) {
            $("#myModal").modal();
            $("#conflict_id").val(result.conflict_id);
            $("#cid").val(result.row_id);
            $("#attrib_01 option[value='" + result.attrib_07 + "']").prop("selected", true);
            $("#attrib_06 option[value='" + result.attrib_06 + "']").prop("selected", true);
            $("#attrib_03 option[value='" + result.attrib_03 + "']").prop("selected", true);
        }
    });
}
    function modelnamelist(){
        var model=$("#attrib_01").val();
        rapid.post({
            url: "/sysadmin/model/getCalmodelList",
            data: "cid=" + model,
            success: function (result) {

                $("#attrib_03").empty();

                if (result.length > 0) {
                    for (let i = 0; i < result.length; i++) {
                        let d = result[i];
                        let txt = "<option value='" + d.attrib_name + "'>" + d.attrib_descn + "</option>"
                        $("#attrib_03").append(txt);
                        choseattrib_03();
                    }

                }

            }
        });
    }

    function calmodelnamelist(){
        var info = $tablez1.bootstrapTable('getSelections');
        rapid.post({
            url: "/sysadmin/model/getCalmodel",
            data: "cid=" + info[0].conflict_id,
            success: function (resultd) {
                $("#myModal1").modal();
                $("#conflict_id_z1").val(resultd.conflict_id);
                $("#cid_z1").val(info[0].conflict_id);
                $("#rowidz1").val(resultd.row_id);
                $("#attrib_02_z1 option[value='" + resultd.attrib_03 + "']").prop("selected", true);

            }
        });

    }

    $z1edit.click(function () {

        var info = $tablez1.bootstrapTable('getSelections');
        var infoz = $table.bootstrapTable('getSelections');
        if (info.length != 1) {
            rapid.info("请选择一行编辑!");
        } else {

            rapid.post({
                url: "/sysadmin/model/getCalmodel",
                data: "cid=" + info[0].conflict_id,
                success: function (resultd) {
                    $("#myModal1").modal();
                    $("#conflict_id_z1").val(resultd.conflict_id);
                    $("#cid_z1").val(info[0].conflict_id);
                    $("#rowidz1").val(resultd.row_id);

                    rapid.post({
                        url: "/sysadmin/model/getCalmodelList1",
                        data: "cid=" + info[0].row_id,
                        success: function (result) {

                            $("#attrib_02_z1").empty();
                            if (result.length > 0) {
                                for (let i = 0; i < result.length; i++) {
                                    let d = result[i];
                                    let txt = "<option value='" + d.attrib_name + "'>" + d.attrib_descn + "</option>"
                                    $("#attrib_02_z1").append(txt);
                                }

                            }
                            calmodelnamelist();
                        }
                    });

                }
            });
        }
    });


    $cdel.click(function () {
        var info = $table.bootstrapTable('getSelections');
        var ids = "";
        for (let i = 0; i < info.length; i++) {
            ids += info[i].conflict_id + ",";

        }

        if (info.length < 1) {
            rapid.info("请至少选择一行删除!");
        } else {
            rapid.post({
                url: "/sysadmin/model/deleteModel",
                data: "ids=" + ids,
                success: function (result) {

                    $table.bootstrapTable('refresh', {query: {pageIndex: 0, pageSize: 10}});
                    $tablez1.bootstrapTable('refresh', {query: {pageIndex: 0, pageSize: 10}});


                }
            });
        }

    });


    $z1del.click(function () {
        var info = $tablez1.bootstrapTable('getSelections');
        var zinfo = $table.bootstrapTable('getSelections');
        var ids = "";
        for (let i = 0; i < info.length; i++) {
            ids += info[i].conflict_id + ",";

        }

        if (info.length < 1) {
            rapid.info("请至少选择一行删除!");
        } else {
            rapid.post({
                url: "/sysadmin/model/deleteCalmodel",
                data: "ids=" + ids,
                success: function (result) {
                    $tablez1.bootstrapTable('destroy');  // 销毁原表格
                    $tablez1.bootstrapTable('refresh', {query: {pageIndex: 1, pageSize: 10}});
                    inittabl1(zinfo[0].row_id);
                }
            });
        }

    });







    $caddbtn.click(function () {

        $("#myModal").modal();
        var model=$("#attrib_01").val();
        rapid.post({
            url: "/sysadmin/model/getCalmodelList",
            data: "cid=" + model,
            success: function (result) {

                $("#attrib_03").empty();

                if (result.length > 0) {
                    for (let i = 0; i < result.length; i++) {
                        let d = result[i];
                        let txt = "<option value='" + d.attrib_name + "'>" + d.attrib_descn + "</option>"
                        $("#attrib_03").append(txt);
                    }

                }

            }
        });

    });

    $("#attrib_01").change(function(){
        var model=$("#attrib_01").val();

        rapid.post({
            url: "/sysadmin/model/getCalmodelList",
            data: "cid=" + model,
            success: function (result) {

                $("#attrib_03").empty();

                if (result.length > 0) {
                    for (let i = 0; i < result.length; i++) {
                        let d = result[i];
                        let txt = "<option value='" + d.attrib_name + "'>" + d.attrib_descn + "</option>"
                        $("#attrib_03").append(txt);
                    }

                }

            }
        });
    });


    $z1addbtn.click(function () {
        var info = $table.bootstrapTable('getSelections');
        if (info.length != 1) {
            rapid.info("请选择一条人员信息!");
        } else {
            $("#rowidz1").val(info[0].row_id);
            $("#cid_z1").val(info[0].row_id);
            $("#myModal1").modal();
            rapid.post({
                url: "/sysadmin/model/getCalmodelList1",
                data: "cid=" + info[0].conflict_id,
                success: function (result) {

                    $("#attrib_02_z1").empty();
                    if (result.length > 0) {
                        for (let i = 0; i < result.length; i++) {
                            let d = result[i];
                            let txt = "<option value='" + d.attrib_name + "'>" + d.attrib_descn + "</option>"
                            $("#attrib_02_z1").append(txt);
                        }

                    }else{

                        $("#attrib_02_z1").empty();
                        let txt = "<option value=''>无可计算字段 </option>"
                        $("#attrib_02_z1").append(txt);
                    }

                }
            });

        }

    });


    $queryBtn.click(function () {
        var searchtext = $("#searchString_id").val();
        $table.bootstrapTable('refresh', {query: {searchval: searchtext}});

        $tablez1.bootstrapTable('destroy');  // 销毁原表格
        inittabl1();

    });


    $('#myModal').on('hidden.bs.modal', function () {
        $("#contactform").data('bootstrapValidator').destroy();
        $('#contactform').data('bootstrapValidator', null);

        $("#conflict_id").val("");
        formValidator($("#contactform"));
        $("#contactform")[0].reset();
    })

    $('#myModal1').on('hidden.bs.modal', function () {
        $("#contactform1").data('bootstrapValidator').destroy();
        $('#contactform1').data('bootstrapValidator', null);
        $("#conflict_id_z1").val("");
        $("#rowidz1").val("");
        formValidator1($("#contactform1"));
        $("#contactform1")[0].reset();
    })


    $('#myModalimp').on('hidden.bs.modal', function () {
        $("#contactformimp").data('bootstrapValidator').destroy();
        $('#contactformimp').data('bootstrapValidator', null);
        formValidatorimp($("#contactformimp"));

        $("#hideFileName").val("");
        for (var i = 0; i < uploader.getFiles().length; i++) {

            uploader.removeFile(uploader.getFiles()[i], true);
            delete uploader.getFiles()[i];
            // 将图片从缩略图容器移除
            var $li = $('#' + uploader.getFiles()[i].id);
            $li.off().remove();

        }
        uploader.reset();


        $("#contactformimp")[0].reset();
    })

    function formValidator(fm) {
        fm.bootstrapValidator({
            message: 'This value is not valid',
            feedbackIcons: {
                /*输入框不同状态，显示图片的样式*/
                valid: 'glyphicon glyphicon-ok',
                invalid: 'glyphicon glyphicon-remove',
                validating: 'glyphicon glyphicon-refresh'
            },
            fields: {
                /*验证*/
                attrib_03: {
                    /*键名username和input name值对应*/
                    validators: {
                        notEmpty: {
                            /*非空提示*/
                            message: '字段名称不能为空'
                        },
//                           stringLength: {/*长度提示*/
//                               min: 6,
//                               max: 30,
//                               message: '用户名在6到30之间'
//                           }/*最后一个没有逗号*/
                    }
                }
            }
        })


    }

    function formValidator1(fm) {
        fm.bootstrapValidator({
            message: 'This value is not valid',
            feedbackIcons: {
                /*输入框不同状态，显示图片的样式*/
                valid: 'glyphicon glyphicon-ok',
                invalid: 'glyphicon glyphicon-remove',
                validating: 'glyphicon glyphicon-refresh'
            },
            fields: {
                /*验证*/
                attrib_02: {
                    /*键名username和input name值对应*/
                    validators: {
                        notEmpty: {
                            /*非空提示*/
                            message: '字段名称不能为空'
                        },
//                           stringLength: {/*长度提示*/
//                               min: 6,
//                               max: 30,
//                               message: '用户名在6到30之间'
//                           }/*最后一个没有逗号*/
                    }
                }/*,
                attrib_02: {
                    /!*键名username和input name值对应*!/
                    validators: {
                        notEmpty: {
                            /!*非空提示*!/
                            message: 'EIM表值不能为空'
                        },
//                           stringLength: {/!*长度提示*!/
//                               min: 6,
//                               max: 30,
//                               message: '用户名在6到30之间'
//                           }/!*最后一个没有逗号*!/
                    }
                }*/

            }
        })


    }


    function formValidatorimp(fm) {
        fm.bootstrapValidator({
            message: 'This value is not valid',
            feedbackIcons: {
                /*输入框不同状态，显示图片的样式*/
                valid: 'glyphicon glyphicon-ok',
                invalid: 'glyphicon glyphicon-remove',
                validating: 'glyphicon glyphicon-refresh'
            },
            fields: {
                /*验证*/
                umdKey: {
                    /*键名username和input name值对应*/
                    validators: {
                        notEmpty: {
                            /*非空提示*/
                            message: '请选择主键'
                        },
//                           stringLength: {/*长度提示*/
//                               min: 6,
//                               max: 30,
//                               message: '用户名在6到30之间'
//                           }/*最后一个没有逗号*/
                    }
                },
                updateRule: {
                    /*键名username和input name值对应*/
                    validators: {
                        notEmpty: {
                            /*非空提示*/
                            message: '请选择更新规则'
                        },
//                           stringLength: {/*长度提示*/
//                               min: 6,
//                               max: 30,
//                               message: '用户名在6到30之间'
//                           }/*最后一个没有逗号*/
                    }
                }

            }
        })


    }


    $("#sava-edit-btn").click(function () {
        $("#contactform").bootstrapValidator('validate');
        var flag = $("#contactform").data('bootstrapValidator').isValid();
        if (flag) {

            rapid.confirm("确定要保存吗？", function (yes) {
                if (yes) {
                    $('#myModal').modal('hide');
                    rapid.post({
                        url: "/sysadmin/model/saveModel",
                        data: $("#contactform").serialize(),
                        success: function (result) {

                            $table.bootstrapTable('refresh', {query: {searchval: ''}})

                        }
                    });
                }
            });
        }


    })

    $("#sava-edit-btn_z1").click(function () {
        var info = $table.bootstrapTable('getSelections');
        $("#contactform1").bootstrapValidator('validate');
        var flag = $("#contactform1").data('bootstrapValidator').isValid();
        if (flag) {

            rapid.confirm("确定要保存吗？", function (yes) {
                if (yes) {
                    $('#myModal1').modal('hide');
                    rapid.post({
                        url: "/sysadmin/model/saveCalmodel?cid="+info[0].conflict_id,
                        data: $("#contactform1").serialize(),
                        success: function (result) {

                            $tablez1.bootstrapTable('refresh');

                        }
                    });
                }
            });
        }


    })


    $("#imp-btn").click(function () {

        $("#contactformimp").bootstrapValidator('validate');
        var flag = $("#contactformimp").data('bootstrapValidator').isValid();
        var hideFileName = $("#hideFileName").val();
        var lx = $("#lx").val();
        if (hideFileName == '') {
            rapid.info("请上传导入数据文件");
            return;
        }
        if (flag) {

            rapid.confirm("确定要导入吗？", function (yes) {
                if (yes) {
                    $('#myModalimp').modal('hide');
                    rapid.post({
                        url: $("#contactformimp")[0].action,
                        data: $("#contactformimp").serialize(),
                        success: function (result) {
                            if (lx == "1") {
                                $tablez1.bootstrapTable('refresh');
                            } else {
                                $table.bootstrapTable('refresh');
                            }

                        }
                    });
                }
            });
        }


    })

    function inittabl1(rid) {
        $tablez1.bootstrapTable({
            url: '/sysadmin/model/getCalModels',
            idField: 'conflict_id',
            dataType: 'json',
            sidePagination: "server", //服务端处理分页
            queryParamsType: "undefined",//设置为 ‘limit’ 则会发送符合 RESTFul 格式的参数.
            queryParams: function (params) {//自定义参数，这里的参数是传给后台的，我这是是分页用的


                return {//这里的params是table提供的
                    pageIndex: params.pageNumber,//从数据库第几条记录开始
                    pageSize: params.pageSize,//找多少条
                    row_id: rid
                }
            },
            responseHandler: function (res) {
                var result = {total: 0, rows: []};

                if (res.recordCount > 0) {
                    result.total = res.recordCount;
                    result.rows = res.list;
                }
                return result;
            },
            sortable: true,

            pagination: 'true',  //开启分页
            paginationPreText: '上一页',
            paginationNextText: '下一页',
            // singleSelect: true, //单选

            showColumns: true,
            clickToSelect: true,
            showRefresh: true,
            columns: [
                {
                    field: 'check', checkbox: true, formatter: function (value, row, index) {
                        if (row.check == true) {
                            //
                            //设置选中
                            return {checked: true};
                        }
                    }
                },
                // {field: 'id', title: '编号', sortable: true, align: 'center'},
                // {field: 'pid', title: '所属上级'},
                {field: 'attrib_02', title: '字段描述', width: 300, class: 'colStyle'},
                {field: 'attrib_03', title: '字段名称', width: 300, class: 'colStyle'},
            ],

            // bootstrap-table-treegrid.js 插件配置 -- start

            //在哪一列展开树形
            treeShowField: 'attrib_02',
            //指定父id列
            parentIdField: 'par_row_id',

            onResetView: function () {

                $tablez1.treegrid({
                    initialState: 'collapsed',// 所有节点都折叠
                    //  initialState: 'expanded',// 所有节点都展开，默认展开
                    treeColumn: 1,
                    expanderExpandedClass: 'glyphicon glyphicon-minus',  //图标样式
                    expanderCollapsedClass: 'glyphicon glyphicon-plus',
                    onChange: function () {
                        $tablez1.bootstrapTable('resetWidth');
                    }
                });

                //只展开树形的第一级节点
                $tablez1.treegrid('getRootNodes').treegrid('expand');

            },
            onCheck: function (row) {

                var datas = $tablez1.bootstrapTable('getData');

                // 勾选子类
                selectChilds(datas, row, "conflict_id", "par_row_id", true);

                // 勾选父类
                selectParentChecked(datas, row, "conflict_id", "par_row_id")

                // 刷新数据
                //    $tablez1.bootstrapTable('load', datas);
            },

            onUncheck: function (row) {
                var datas = $tablez1.bootstrapTable('getData');

                selectChilds(datas, row, "conflict_id", "par_row_id", false);
                //   $tablez1.bootstrapTable('load', datas);
            },
            onClickRow: function (row, $element) {
                $tablez1.bootstrapTable('uncheckAll');
                var datas = $tablez1.bootstrapTable('getData');
                //   console.log(datas);
                row.check = true;
                // $tablez1.bootstrapTable('load', datas);


            }

            // bootstrap-table-treetreegrid.js 插件配置 -- end
        });

    }

    function changeDateFormat(cellval) {
        var val = cellval + "";

        if (val != '' && val != null && val != 'null' && val != 'undefined') {
            return val.substring(0, 10)
        }

    }


    $table.bootstrapTable({
        url: "/sysadmin/model/getModels",
        idField: 'conflict_id',
        dataType: 'json',


        sidePagination: "server", //服务端处理分页
        queryParamsType: "undefined",//设置为 ‘limit’ 则会发送符合 RESTFul 格式的参数.
        queryParams: function (params) {//自定义参数，这里的参数是传给后台的，我这是是分页用的
//            请求服务器数据时，你可以通过重写参数的方式添加一些额外的参数，例如 toolbar 中的参数 如果
//　　　　　　　queryParamsType = 'limit' ,返回参数必须包含limit, offset, search, sort, order
//            queryParamsType = 'undefined', 返回参数必须包含: pageSize, pageNumber, searchText, sortName, sortOrder.
//            返回false将会终止请求。


            $tablez1.bootstrapTable('destroy');  // 销毁原表格
            inittabl1();

            return {//这里的params是table提供的
                pageIndex: params.pageNumber,//从数据库第几条记录开始
                pageSize: params.pageSize,//找多少条
                searchval: $("#searchString_id").val(), //这个就是搜索框中的内容，可以自动传到后台，搜索实现在xml中体现
            }
        },
        responseHandler: function (res) {
            var result = {total: 0, rows: []};

            if (res.recordCount > 0) {
                result.total = res.recordCount;
                result.rows = res.list;
            }
            return result;
        },
        sortable: true,

        pagination: 'true',  //开启分页
        paginationPreText: '上一页',
        paginationNextText: '下一页',
        // singleSelect: true, //单选

        showColumns: true,
        // clickToSelect: true,
        showRefresh: true,
        columns: [
            {
                field: 'check', checkbox: true, formatter: function (value, row, index) {

                    if (row.check == true) {

                        //设置选中


                        return {checked: true};
                    }
                }
            },
            {field: 'attrib_01', title: '模型描述', width: 300, class: 'colStyle'},
            {field: 'attrib_02', title: '模型名称', class: 'colStyle'},
            {field: 'attrib_04', title: '字段名称', class: 'colStyle'},
            {field: 'attrib_06', title: '计算规则', class: 'colStyle'},
        ],

        // bootstrap-table-treegrid.js 插件配置 -- start

        //在哪一列展开树形
        treeShowField: 'eim_source',
        //指定父id列
        parentIdField: 'par_row_id',

        onResetView: function () {

            $table.treegrid({
                initialState: 'collapsed',// 所有节点都折叠
                //  initialState: 'expanded',// 所有节点都展开，默认展开
                treeColumn: 1,
                expanderExpandedClass: 'glyphicon glyphicon-minus',  //图标样式
                expanderCollapsedClass: 'glyphicon glyphicon-plus',
                onChange: function () {
                    $table.bootstrapTable('resetWidth');
                }
            });

            //只展开树形的第一级节点
            $table.treegrid('getRootNodes').treegrid('expand');

        },
        onCheck: function (row) {

            var datas = $table.bootstrapTable('getData');

            // 勾选子类
            selectChilds(datas, row, "conflict_id", "par_row_id", true);

            // 勾选父类
            selectParentChecked(datas, row, "conflict_id", "par_row_id")
            $('.changeColor').removeClass('changeColor');

            /*var result = {total: 0, rows: []};
            var total = 0;


            if (datas.length > 0) {
                rapid.post({
                    url: "/sysadmin/zsjgl/getContactsSize",
                    data: "searchval=" + $("#searchString_id").val(),
                    async: false,
                    success: function (ts) {

                        total = ts.ucont;
                    }
                });
                result.total = total;
                result.rows = datas;
            }

            // 刷新数据
            $table.bootstrapTable('load', result);*/
        },

        onUncheck: function (row) {
            var datas = $table.bootstrapTable('getData');
            selectChilds(datas, row, "conflict_id", "par_row_id", false);
            /*  var result = {total: 0, rows: []};
              var total = 0;


              if (datas.length > 0) {
                  rapid.post({
                      url: "/sysadmin/zsjgl/getContactsSize",
                      data: "searchval=" + $("#searchString_id").val(),
                      async: false,
                      success: function (ts) {
                          total = ts.ucont;
                      }
                  });
                  result.total = total;
                  result.rows = datas;
              }

              // 刷新数据
              $table.bootstrapTable('load', result);*/
        },
        onClickRow: function (row, $element) {
            $table.bootstrapTable('uncheckAll');
            var datas = $table.bootstrapTable('getData');
            row.check = true;


            /*

                        var result = {total: 0, rows: []};
                        var total=0;


                        if (datas.length > 0) {
                            rapid.post({
                                url: "/sysadmin/dbcontact/getContactsSize",
                                async: false,
                                success: function (ts) {
                                    total =ts.recordCount;
                                }
                            });
                            result.total=total;
                            result.rows = datas;
                        }

                        // 刷新数据
                        $table.bootstrapTable('load', result);*/
            $('.selected').removeClass('selected');
            $('.changeColor').removeClass('changeColor');
            $($element).addClass('changeColor');
            //这个就是搜索框中的内容，可以自动传到后台，搜索实现在xml中体现
            $tablez1.bootstrapTable('destroy');  // 销毁原表格
            inittabl1(row.row_id);

        }

        // bootstrap-table-treetreegrid.js 插件配置 -- end
    });

    $(document).ready(function () {
        formValidator($("#contactform"));
        formValidator1($("#contactform1"));

        formValidatorimp($("#contactformimp"));
        __bindRdetailformuploadinit();
        inittabl1();

    });
});


/*
$table.on('click-row.bs.table', function (e,row,$element) {
    $('.changeColor').removeClass('changeColor');
    $($element).addClass('changeColor');

});
*/


/**
 * 选中父项时，同时选中子项
 * @param datas 所有的数据
 * @param row 当前数据
 * @param id id 字段名
 * @param pid 父id字段名
 */
function selectChilds(datas, row, id, pid, checked) {
    for (var i in datas) {
        if (datas[i][pid] == row[id]) {

            datas[i].check = checked;
            selectChilds(datas, datas[i], id, pid, checked);
        }
        ;
    }
}


/**
 * 选中父项时，同时选中子项
 * @param datas 所有的数据
 * @param row 当前数据
 * @param id id 字段名
 * @param pid 父id字段名
 */


function selectParentChecked(datas, row, id, pid) {
    for (var i in datas) {
        if (datas[i][id] == row[pid]) {
            datas[i].check = true;
            selectParentChecked(datas, datas[i], id, pid);
        }
        ;
    }
}

function test() {
    var selRows = $table.bootstrapTable("getSelections");
    if (selRows.length == 0) {
        alert("请至少选择一行");
        return;
    }

    var postData = "";
    $.each(selRows, function (i) {
        postData += this.id;
        if (i < selRows.length - 1) {
            postData += "， ";
        }
    });
    alert("你选中行的 id 为：" + postData);

}


$('#myTab a').click(function (e) {
    e.preventDefault();
    $(this).tab('show');
})
